package boss;

import java.util.concurrent.CountDownLatch;

public class TestThread {

    private static Object o = new Object();
    private static volatile int flag = 0;

    public static void main(String[] args) {
        long mainStart = System.currentTimeMillis();
        // A-65  a-97
        new Thread(()->{
            long start = System.currentTimeMillis();
            for(int i=97; i<123;){
                synchronized (o){
                    if(flag==0){
                        System.out.printf(""+(char)i);
                        i++;
                        flag = 1;
                        o.notify();
                    }else {
                        try {
                            o.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
            long end = System.currentTimeMillis();
            System.out.println();
            System.out.println("t1 total time:"+(end-start));
        }).start();

        new Thread(()->{
            long start = System.currentTimeMillis();
            for(int i=65; i<91;){
                synchronized (o){
                    if(flag==1){
                        System.out.printf(""+(char)i);
                        i++;
                        flag = 0;
                        o.notify();
                    }else {
                        try {
                            o.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
            long end = System.currentTimeMillis();
            System.out.println("t2 total time:"+(end-start));
        }).start();

        long mainEnd = System.currentTimeMillis();
        System.out.println("t1&t2 total time:"+(mainEnd-mainStart));

    }
}
